<template>
    <div class="page-container">
        <div class="page-header">
            <div class="page-header-title-bg"></div>
            <!-- 推荐商品 -->
            <div class="page-header-recommend">
                <ul>
                    <li v-for="(itemInfo, index) in recommentListData" :key="itemInfo.name">
                        <div class="recommend-item">
                            <div class="item-content">
                                <img :src="itemInfo.img" alt="" />
                            </div>
                            <div class="item-name">
                                <span>{{ itemInfo.name }}</span>
                            </div>
                        </div>
                    </li>
                </ul>
                <div class="direction-indication"></div>
            </div>
        </div>
        <div class="page-body">
            <!-- <swiper :slidesPerView="3" :spaceBetween="30" class="mySwiper">
                <swiper-slide>Slide 1</swiper-slide>
                <swiper-slide>Slide 2</swiper-slide><swiper-slide>Slide 3</swiper-slide>
                <swiper-slide>Slide 4</swiper-slide><swiper-slide>Slide 5</swiper-slide>
                <swiper-slide>Slide 6</swiper-slide><swiper-slide>Slide 7</swiper-slide>
                <swiper-slide>Slide 8</swiper-slide><swiper-slide>Slide 9</swiper-slide>
            </swiper> -->
            <div class="product-container">
                <!-- 一行单个商品展示 -->
                <div class="product-item-one">
                    <img src="@public/img/product_list/1.png" alt="" />
                </div>

                <!-- 一行两个商品展示的商品列表 -->
                <div class="product-two-container">
                    <div class="product-item-two">
                        <img src="@public/img/product_list/2.png" alt="" />
                    </div>
                    <div class="product-item-two">
                        <img src="@public/img/product_list/2.png" alt="" />
                    </div>
                    <div class="product-item-two">
                        <img src="@public/img/product_list/2.png" alt="" />
                    </div>
                    <div class="product-item-two">
                        <img src="@public/img/product_list/2.png" alt="" />
                    </div>
                </div>

                <!-- 商品类别导航 -->
                <div class="product-nav-tab">
                    <ul>
                        <li v-for="(categoryInfo, index) in productCategoryList" @click="selectCategory = categoryInfo"
                            :class="{ focus: selectCategory === categoryInfo }" :key="categoryInfo.title">
                            <div class="nav-tab-item">
                                {{ categoryInfo.title }}
                            </div>
                        </li>
                    </ul>
                </div>

                <!-- 导航类别对应的商品 -->
                <div class="product-two-container">
                    <div class="product-item-two" v-for="itemInfo in selectCategory.items" :key="itemInfo.name">
                        <RouterLink :to="itemInfo.url" custom v-slot="{ isActive, href, navigate }">
                            <img @click="navigate" :src="itemInfo.img" alt="" />
                        </RouterLink>
                    </div>
                </div>

            </div>
        </div>
    </div>
</template>

<script lang="ts" setup>

// 路由链接组件
import { ref } from 'vue';
import { RouterLink } from 'vue-router'

// import { Swiper, SwiperSlide } from 'swiper/vue';
// import 'swiper/css';

import productStoreUse from '@/model/product.model';

const productStore = productStoreUse();

// 推荐商品
const recommentListData = productStore.recommendData;
// 商品类别列表
const productCategoryList = productStore.productCategoryList;
// 选中的类别
const selectCategory = ref(productCategoryList[1]);


</script>

<style>
.swiper {
    width: 100%;
    height: 150px;
}

.swiper-slide {
    text-align: center;
    font-size: 18px;
    background: #fff;

    /* Center slide text vertically */
    display: flex;
    justify-content: center;
    align-items: center;
}

.swiper-slide img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}
</style>

<style scoped lang="less">
@main-width: 375px;

@product-container-width: @main-width - 26px;

.page-container {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    background-color: @bgcolor;
}

.page-header {
    height: 500px;
    display: flex;
    padding-top: 30px;
    flex-direction: column;
    justify-content: space-between;
    background-repeat: no-repeat;
    background-position-x: center;
    background-position-y: -15px;
    background-size: 100%;
    background-image: url("@assets/img/master/title_bg.png");
}

.page-header-title-bg {
    width: 100%;
    height: 100px;
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    background-image: url("@assets/img/master/index_title_content.png");
}


.page-header-recommend {
    width: 100%;
    height: 115px;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    padding: 10px 20px 10px 15px;
    // background-color: pink;
    background-repeat: no-repeat;
    background-position: center;
    background-size: @main-width - 18px 100%;
    background-image: url("@assets/img/master/header-recomment-bg.png");

    ul {
        width: 100%;
        height: 100%;
        padding: 0;
        flex: 1;
        display: flex;
        overflow-x: auto;
        padding: 3px;
        -webkit-overflow-scrolling: touch;
    }

    li {
        list-style: none;
    }

    .recommend-item {
        width: 75px;
        height: 100%;
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        align-items: center;
        // border: solid 1px pink;


        .item-content {
            width: 100%;
            height: 50px;
            display: flex;
            background-repeat: no-repeat;
            background-position: center;
            background-size: contain;
            justify-content: center;
            align-items: center;
            background-image: url("@assets/img/master/recommend_bg.png");

            img {
                width: 46px;
                height: auto;
            }
        }

        .item-name {
            color: white;
            display: flex;
            font-size: 10px;
            width: 165px * 0.35;
            height: 66px * 0.35;
            background-repeat: no-repeat;
            background-position: center;
            background-size: 100% 100%;
            justify-content: center;
            align-items: center;
            background-image: url("@assets/img/master/tab_focus.png");
        }
    }
}

.direction-indication {
    width: 23px;
    height: 100%;
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    background-image: url("@assets/img/master/direction_indication.png");
}

.page-body {
    width: 100%;
    padding-top: 10px;
    padding-bottom: 100px;
    background-repeat: no-repeat;
    background-position-x: center;
    background-position-y: bottom;
    background-size: contain;
    background-image: url("@assets/img/master/footer_texture.png");



    .product-container {
        min-height: 600px;
        margin: 0 auto;
        width: @product-container-width;
        // border: solid 1px red;
    }

    .product-item-one {
        width: 100%;
        position: relative;
        // padding: 2px 3px 3px 2px;
        overflow: hidden;
        font-size: 0;
        min-height: @product-container-width - 38px;

        &::after {
            top: 0;
            left: 0;
            content: '';
            display: block;
            clear: both;
            width: 100%;
            height: 100%;
            position: absolute;
            background-repeat: no-repeat;
            background-position: center;
            background-size: 100% 100%;
            background-image: url("@assets/img/master/large_box.png");
        }

        img {
            width: 100%;
        }
    }

    .product-two-container {
        display: flex;
        flex-wrap: wrap;
        padding-top: 5px;
        justify-content: space-between;
    }

    .product-item-two {
        width: (@product-container-width / 2) - 3px;
        position: relative;
        // padding: 2px 3px 3px 2px;
        overflow: hidden;
        font-size: 0;
        margin-top: 10px;
        min-height: (@product-container-width / 2) - 20px;

        &::after {
            top: 0;
            left: 0;
            content: '';
            display: block;
            clear: both;
            width: 100%;
            height: 100%;
            position: absolute;
            background-repeat: no-repeat;
            background-position: center;
            background-size: 100% 100%;
            background-image: url("@assets/img/master/small_box.png");
        }

        img {
            width: 100%;
        }
    }

    .product-nav-tab {
        width: 100%;
        padding-top: 20px;

        ul {
            padding: 0;
            width: 100%;
            display: flex;
            overflow-x: scroll;

            li {
                list-style: none;
                padding-right: 8px;


                &.focus {
                    .nav-tab-item {
                        color: white;
                        font-weight: bold;
                        background-image: url("@assets/img/master/tab_focus.png");
                    }
                }
            }

            .nav-tab-item {
                color: rgb(255 220 220 / 69%);
                display: flex;
                font-size: 16px;
                width: 165px * 0.6;
                height: 66px * 0.6;
                background-repeat: no-repeat;
                background-position: center;
                background-size: 100% 100%;
                justify-content: center;
                align-items: center;
                background-image: url("@assets/img/master/tab_normal.png");
            }
        }
    }
}
</style>